<?
class JSCompressor
{
    static function Process($script)
    {
        // "//"
		$script = preg_replace('/\/\/.*$/m','', $script ) ;
		
		// ";"
		$script = preg_replace(
			'/\s*(?=;\s*$)/m',
			'', $script ) ;

		// "="
		$script = preg_replace(
			'/^([^"\'\r\n]*?)\s*=\s*/m',
			'$1=', $script ) ;

		// "()": "( var )" = "(var)"
		$script = preg_replace(
			'/^([^\r\n""\']*?\()\s+(.*?)\s+(?=\)[^\)]*$)/m',
			'$1$2', $script ) ;

		//  [;{}] 
		$script = preg_replace(
			'/(?<![;{}\n\r\s])\s*[\n\r]+\s*(?![\s\n\r{}])/s',
			' ', $script ) ;

		$script = preg_replace(
			'/\s*}\s*[\n\r]+\s*(?!\s*(else|catch|finally|while|[}\),;]))/s',
			'};', $script ) ;

		// \n\r
		$script = preg_replace(
			'/(^\s*$)|(^\s+)|(\s+$\n)/m',
			'', $script ) ;
		return $script;    
    }
    
}
?>